package com.by.biz.impl;

import com.by.biz.IUserBiz;
import com.by.dao.IUserDao;
import com.by.model.User;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service("userBiz")
public class UserBizImpl implements IUserBiz {
    @Autowired
    private IUserDao iUserDao;

    @Override
    public List<User> getAll() {
        return iUserDao.getAll();
    }

    @Override
    public int addUser(User user) {
        return iUserDao.addUser(user);
    }

    @Override
    public int delUser(User user) {
        return iUserDao.delUser(user);
    }

    @Override
    public User getUser(User user) {
        return iUserDao.getUser(user);
    }

    @Override
    public void editUser(User user) {
        iUserDao.editUser(user);
    }

    @Override
    public User loginUser(User user) {
        return iUserDao.loginUser(user);
    }

    @Override
    public int addreg(User user) {
        return iUserDao.addreg(user);
    }

    @Override
    public Page queryLikeUsers(Map<String, Object> cond) {
        Page page = new Page();
        //根据条件查询符合条件的记录总数，赋值给page的totalNum变量
        page.setTotal(iUserDao.getLikeUsersCount(cond));
        //从请求参数中获得每页的大小
        int pageSize = Integer.parseInt(String.valueOf(cond.get("pageSize")));
        page.setPageSize(pageSize);
        //从请求参数中获得当前页码
        int pageNum = Integer.parseInt(String.valueOf(cond.get("pageNum")));
        page.setPageNum(pageNum);
        //计算总页数
        page.setPageNum((int) (page.getTotal() / page.getPageSize() + (page.getTotal() % pageSize == 0 ? 0 : 1)));
        //根据条件查询符合的用户列表，赋值给pape的result变量
        page = PageHelper.startPage(pageNum, pageSize);
        List list = iUserDao.getLikeUsers(cond);
        return page;
    }
}
























